package com.kfyang.manualgear.util;

import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.MethodSpec;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;

public interface ElementUtils {
    /**
     * 复制注解到实现类上
     * @param element 方法元素
     * @param methodBuilder 方法构造器
     */
    static void copyAnnotations(Element element, MethodSpec.Builder methodBuilder) {
        if (GlobalConfigUtils.copyAnnotations != null) {
            for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
                if (GlobalConfigUtils.copyAnnotations.contains(annotationMirror.getAnnotationType().toString())) {
                    methodBuilder.addAnnotation(AnnotationSpec.get(annotationMirror));
                }
            }
        }
    }
}
